package com.yuandian.api.customer_perception.po;

import com.yuandian.po.BasePageSearch;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;

/**
 * 说明：高频告警请求对象
 * @Author yanjun
 * @Date 2021/5/10 8:46
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class HighFrequencyAlarmParams extends BasePageSearch {

    private static final long serialVersionUID = -7576727475554862660L;

    private static final DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyyMMdd");

    /**
     * 系统id
     */
    private Integer systemId;
    private String systemName;

    /**
     * 业务编码
     */
    private List<String> businessCode;

    /**
     * 告警类型(告警指标id)
     */
    private Integer alarmIndicatorId;

    /**
     * 故障类型(告警返回码)
     */
    private String alarmResultCode;

    /**
     * 统计类型
     */
    private List<String> statType;

    /**
     * 失败率大于
     */
    private Double gtFailRate;

    /**
     * 查询时间
     */
    private List<String> queryTimeList;


    public void handleQueryTime () {
        queryTimeList = new ArrayList<>();

        LocalDate nowDay = LocalDate.now();

        // 连续 7 天
        for (int i = 7; i > 0; i--) {
            LocalDate tmp = nowDay.minusDays(i);
            queryTimeList.add(dtf.format(tmp));
        }
    }

    public void handleQueryParam () {

        if (null == businessCode || businessCode.size() == 0) {
            businessCode = null;
        }


        if (null == statType || statType.size() == 0) {
            statType = null;
        }

        if (null == alarmResultCode || alarmResultCode.trim().length() == 0) {
            alarmResultCode = null;
        }

        if (null == alarmIndicatorId || alarmIndicatorId == 0) {
            alarmIndicatorId = null;
        }
    }
}
